package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 *
 */
public class AlertConf
        extends CapiPassiveMessage
        implements InfoAccessor, PlciAccessor {

    /** The offset of the PLCI within the message. */
    private static final int OFFSET_PLCI = OFFSET_MESSAGE;

    /** The offset of the info struct within the message. */
    private static final int OFFSET_INFO = OFFSET_MESSAGE + SIZE_OF_PLCI;

    /**
     * Create a new {@code AlertConf} from the specified {@code ByteBuffer}.
     *
     * @param byteBuffer A {@code ByteBuffer} containing a ALERT_CONF message.
     */
    public AlertConf(final ByteBuffer byteBuffer) {
        super(byteBuffer);
    }

    /** {@inheritDoc} */
    public int getPlci() {
        return getByteBuffer().getInt(OFFSET_PLCI);
    }

    /** {@inheritDoc} */
    public ErrorInfo getInfo() {
        return ErrorInfo.valueOf(getByteBuffer().getShort(OFFSET_INFO));
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format(
                "%s[%s plci=0x%08x info=%s]",
                getClass().getSimpleName(),
                super.toString(),
                getPlci(),
                getInfo());

        return s;
    }

}
